package edu.uic.cs.i422.s2011.team4;



import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class viewMap extends MapActivity {
	private ArrayList<Integer> xcoord;
	private ArrayList<Integer> ycoord;
	int currentPosition = 0;
	Drawable drawable;
	List<Overlay> mapOverlays;
	int i = 0;
	MapView mapView = null;
	MapController mapControl;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       
		LinearLayout layout = new LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL); // Set Orientation
		layout.setScrollContainer(true);
        
        SquirrelUIGenerator squirrel = new SquirrelUIGenerator(this);
		squirrel.setTitle(R.string.siteListingTitle);
		squirrel.setHelp(R.string.siteListingHelp);
		squirrel.setBreadCrumb(R.string.siteListingBreadCrumb);
		
		
		LinearLayout listLayout = (LinearLayout) View.inflate(this, R.layout.map, null);
        
		// Inflate
//		mapView = (MapView) View.inflate(this,R.id.mapview, null);
		

		
//		MapView mapView = (MapView) findViewById(R.id.mapview);
		MapView mapView = new MapView(this,"0qfmBIEW15hnSoNtEWEqwGoDfdzQkysVXut6ezw");
	//	 mapView.inf
        // Add buttons - ListView, NewSite, Delete
       
        mapView.setBuiltInZoomControls(true);
        mapView.setStreetView(true);
        mapView.setClickable(true);
        
        
        listLayout.addView(mapView);
		layout.addView(squirrel.getHeader());
		layout.addView(listLayout);

        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.yellow_placemark);
     //   Toast.makeText(getApplicationContext(), "coord " + SiteList.xCoord.get(0), 2).show();
 /*       for (i = 0; i < SquirrelData.getSize(); i++){
        	
        	MapOverlay itemizedoverlay = new MapOverlay(drawable,mapView.getContext(),SquirrelData.getSiteName(i));
       // 	Toast.makeText(getApplicationContext(), "coord " + xcoord.get(i), 2).show();
            GeoPoint point = new GeoPoint(xcoord.get(i),ycoord.get(i));
         	OverlayItem overlayitem = new OverlayItem(point, SquirrelData.getSiteName(i), "");
            itemizedoverlay.addOverlay(overlayitem);
     //       mapOverlays.add(itemizedoverlay);
        	
        }  */
		MapOverlay itemizedoverlay = new MapOverlay(drawable,mapView.getContext(),SquirrelData.selectedSite);
	//	Log.d("xCoord",SquirrelData.getXCoordinate() + " -- " +  SquirrelData.getYCoordinate());
		GeoPoint point = new GeoPoint((int) SquirrelData.getXCoordinate(),(int) SquirrelData.getYCoordinate());

        OverlayItem overlayitem = new OverlayItem(point,SquirrelData.selectedSite,"");
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        int maxZoom = mapView.getMaxZoomLevel();
        int initZoom = (int)(0.80*(double)maxZoom);
        mapControl = mapView.getController();
        mapControl.setZoom(initZoom);
        mapControl.animateTo(point);

        setContentView(layout);
    	/**
		 * Make a button and add click listeners
		 */
/*		Button btnSimple = (Button) findViewById(R.id.mapViewButton);
		btnSimple.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				Toast.makeText(getApplicationContext(),
						" You clicked the new site button", Toast.LENGTH_SHORT)
						.show();

				Intent intent = new Intent(v.getContext(), SliderTrees.class);
				startActivity(intent);
				finish();
			}
		});

		btnSimple = (Button) findViewById(R.id.mapDeleteButton);
		btnSimple.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				Toast.makeText(
						getApplicationContext(),
						" You removed the " + siteNames.get(currentPosition)
								+ " listing", Toast.LENGTH_SHORT).show();
				siteNames.remove(currentPosition);
	//			writeXmlData();
				Intent intent = new Intent(v.getContext(), SiteList.class);
				startActivity(intent);
				finish();
			}
		});
		
		btnSimple = (Button) findViewById(R.id.mapViewButton);
		btnSimple.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				Toast.makeText(
						getApplicationContext(),
						" You removed the " + siteNames.get(currentPosition)
								+ " listing", Toast.LENGTH_SHORT).show();
				Intent intent = new Intent(v.getContext(), viewMap.class);
				startActivity(intent);
				finish();
			}
		});
        */
    
    
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}
